package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Document;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class DocumentDao {

	private DBHelp<Document> db = new DBHelp<Document>();
	
	public void save(Document doc) {
		String sql = "insert into t_file(name,filename) values(?,?)";
		db.executeSQL(sql, doc.getName(),doc.getFileName());
	}
	
	public List<Document> findAll() {
		String sql = "select id,name,filename from t_file";
		return db.executeQueryForList(sql, new DocumentRowMapper());
	}
	
	
	private class DocumentRowMapper implements RowMapper<Document> {

		public Document mapRow(ResultSet rs) throws SQLException {
			Document d = new Document();
			d.setFileName(rs.getString("fileName"));
			d.setId(rs.getInt("id"));
			d.setName(rs.getString("name"));
			return d;
		}
		
	}
	
	
	
	
	
	
	
}
